
/**
 * 查找父级路径
 * @param path 当前路径
 * @param menuData 菜单数据
 * @returns 父级路径数组
 */
export const findParentKey = (path: string, menuData: any[]) => {
    const result: any[] = [];
    const map = new Map(menuData.map(item => [item.id, item]))
    menuData.forEach(it => {
        map.set(it.id, it)
    })
    let currentMenu = map.get(menuData.find(item => item.path === path)?.id)
    while (currentMenu) {
        result.push(currentMenu.path)
        if (!currentMenu.parentId || currentMenu.parentId === '0') {
            break
        }
        currentMenu = map.get(currentMenu.parentId)
    }
    return result
}



/**
 * 获取当前路径
 * @param menu 菜单数据
 * @returns 当前路径
 */

export const getCurrentPath = (menu: any[]) => {
    const result: string[] = []
    let currentMenu = menu[0]
    while (currentMenu) {
        result.push(currentMenu.path)
        if (currentMenu.children || currentMenu.children.length === 0) {
            break
        }
        currentMenu = currentMenu.children[0]
    }
    return result.length > 0 ? `/${result.join('/')}` : '';
}